package ooday03;
//引用类型数组的演示
public class RefArrayDemo {
    public static void main(String[] args) {
        //引用类型数组的定义
        //声明Dog型数组dogs,包含3个元素,每个元素都是Dog类型,默认值为null
        Dog[] dogs = new Dog[3];
        //声明Chick型数组chicks,包含5个元素，每个元素类型都是Chick类型,默认值为null
        Chick[] chicks = new Chick[2];
        //声明Fish型数组fishs,包含4个元素,每个元素都是Fish类型,默认值为null
        Fish[] fishs = new Fish[4];

        dogs[0]=new Dog("小黑",32,"黑");
        dogs[1]=new Dog("小白",33,"白");
        dogs[2]=new Dog("小灰",34,"灰");
        dogs[0].name="小黑黑";
        dogs[1].age=45;
        for (int i=0;i<dogs.length;i++){
            dogs[i].swim();
        }
        System.out.println(dogs[0].name);
        dogs[2].swim();

        chicks[0]= new Chick("小花",1,"花");
        chicks[1]= new Chick("大花",2,"花");
        for (int i=0;i<chicks.length;i++){
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }

        fishs[0] = new Fish("小金",2,"金");
        fishs[1] = new Fish("大金",4,"白");
        fishs[2] = new Fish("小绿",1,"绿");
        fishs[3] = new Fish("小红",2,"红");
        for (int i=0;i<fishs.length;i++){
            System.out.println(fishs[i].color);
            fishs[i].swim();
        }
    }
}
